package org.systemsbiology.addama.sequencing.util;

import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;

/**
 * Created by IntelliJ IDEA.
 * User: jlin
 * Date: Apr 21, 2010
 * Time: 4:04:39 PM
 * To change this template use File | Settings | File Templates.
 */
public class Formatter {


    public static String getDateString(Date date, String format) {
        DateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.format(date);
    }

    public static void main(String [ ] args)
    {
        Formatter t = new Formatter();
        System.out.println(t.getDateString(new Date(), "yyyy/MM/dd HH:mm:ss"));

        System.out.println(t.getDateString(new Date(), "MM/dd/yyyy"));
    }

     private String replaceSpaces(String uri) {
        return StringUtils.replace(uri, " ", "%20");
    }

    private String getValue(String value, String defaultValue) {
        String cleanValue = StringUtils.replace(value, "\"", "");
        if (StringUtils.isEmpty(cleanValue) || StringUtils.equalsIgnoreCase(cleanValue, "null")) {
            return defaultValue;
        }
        return cleanValue;
    }

    public static String getHttpsUrl(HttpServletRequest request) {
        StringBuilder builder = new StringBuilder();
        builder.append("https://");
        builder.append(request.getServerName());
        builder.append(":").append("8443");
        return builder.toString();
    }

}
